Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Namespace NVPortal.Modules.NVNews

    Public MustInherit Class SpecialDefault
        Inherits Entities.Modules.PortalModuleBase

#Region "Controls"
#End Region

#Region "Event Handlers"
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Not IsPostBack Then

                    Dim DisplayNumber As String
                    If Settings("NVNewsDisplayNumberSetting") <> "" Then
                        DisplayNumber = Settings("NVNewsDisplayNumberSetting")
                    Else
                        DisplayNumber = "1" ' 1 row and 1 col
                    End If

                    'Cac tin khac cung chuyen muc voi tin nay
                    Dim arrNews As New ArrayList
                    Dim ctlNews As New NV_NewsController
                    arrNews = ctlNews.SelectCustomeNews(IIf(Settings("NVNewsCategorySetting") <> "", Settings("NVNewsCategorySetting"), 0), Settings("PortalSetting"), CInt(DisplayNumber) + 1)
                    If arrNews.Count > 0 Then
                        Dim objNews As NV_NewsInfo
                        objNews = CType(arrNews(0), NV_NewsInfo)
                        Me.lbSummary.Text = objNews.Summary
                        Me.hplRSS.NavigateUrl = "/Feed/danhmuc/" & objNews.CategoryId & ".aspx"
                        Me.hplTitle.Text = objNews.Title
                        Me.hplTitle.NavigateUrl = FormatURL("tin", objNews.NewId, "danhmuc", objNews.CategoryId, ReplaceChuoi(objNews.Title))
                        Me.hplimg2.NavigateUrl = FormatURL("tin", objNews.NewId, "danhmuc", objNews.CategoryId, ReplaceChuoi(objNews.Title))
                        'Me.imgNews.ImageUrl = PortalSettings.HomeDirectory & "news/" & objNews.ImagePath

                        If objNews.ImagePath.Contains("http://") Then
                            Me.imgNews.Visible = True
                            Me.imgNews.ImageUrl = objNews.ImagePath
                        Else
                            Me.imgNews.Visible = True
                            Me.imgNews.ImageUrl = PortalSettings.HomeDirectory & "news/" & objNews.ImagePath
                        End If
                        If Settings("NVNewsImageValueSetting") <> "" Then
                            Me.imgNews.Width = CInt(Split(Settings("NVNewsImageValueSetting"))(0))
                        Else
                            Me.imgNews.Width = 60
                        End If

                        If Me.lbSummary.Visible = False Then
                            Me.hplTitle.ToolTip = objNews.Summary
                        End If
                        arrNews.RemoveAt(0)
                        Me.drgOtherNews.DataSource = arrNews
                        Me.drgOtherNews.DataBind()
                    End If

                End If
            Catch ex As Exception
                'Me.imgNews.Visible = False
                ' Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub
        Public Function ReplaceChuoi(ByVal chuoi As String) As String
            Dim convert As String = Global.ReplaceChuoi.bodau(chuoi).Replace(" ", "-")
            Return convert
        End Function
        Public Function FormatURL(ByVal sitem As String, ByVal strID As String, ByVal scat As String, ByVal strCatID As String, ByVal strLink As String) As String
            Dim tabshow As Integer
            tabshow = Settings("NVNewsDisplayPageSetting")
            Return "/tabid/" & tabshow & "/" & scat & "/" & strCatID & "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".aspx"
        End Function

#End Region

#Region "Optional Interfaces"

#End Region


    End Class

End Namespace
